﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：开户
//********************************************************************************//
using System;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.YongHuGL
{
    public partial class KaiHu : BasePage
    {
        #region 属性

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int YONGHUXXID
        {
            get
            {
                return Convert.ToInt32(ViewState["_YONGHUXXID"]);
            }
            set
            {
                ViewState["_YONGHUXXID"] = value;
            }
        }
     
        /// <summary>
        /// 记录合同号
        /// </summary>
        private string HETONGH
        { 
            get
            {
                return Convert.ToString(ViewState["HETONGH"]);
            }
            set
            {
                ViewState["HETONGH"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 用户信息对象
        /// </summary>
        YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
                InitData();
                Display();
            }
        }

        /// <summary>
        /// 添加操作
        /// </summary>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            InitData();
            this.Status = GridViewStatus.Add;
            Display();
        }

        /// <summary>
        /// 放弃操作
        /// </summary>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.Status = GridViewStatus.Init;
            Display();
            //如果当前有成功操作的记录,放弃则重新加载记录信息
            if(this.YONGHUXXID>0)
            {
                SetData();
            }
        }

        /// <summary>
        /// 修改操作
        /// </summary>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            this.Status = GridViewStatus.Update;
            Display();
        }

        /// <summary>
        /// 保存操作
        /// </summary>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                SaveData();
            }    
        }     
       
        /// <summary>
        /// 承诺付费复选框选中状态变化事件
        /// </summary>
        protected void cbChengNuo_CheckedChanged(object sender, EventArgs e)
        {
            if (this.cbChengNuo.Checked)
            {
                this.cbTuoShou.Checked = false;
            }
            else
            {
                this.cbTuoShou.Enabled = true;
            }
        }

        /// <summary>
        /// 根据管理块加载用水性质
        /// </summary>
        protected void cmbYongShuiXZ_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            PageTools.LoadComboxYongShuiXZByGuanLiK(this.cmbYongShuiXZ, this.cmbGuanLiK.Value.ToString(), "-", null);
        }

        /// <summary>
        /// 加载公司下拉框
        /// </summary>
        protected void cmbGongSi_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            PageTools.LoadComboxGongSi((DevExpress.Web.ASPxComboBox)sender, Convert.ToString(this.cmbJu.Value), null);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            if (e.Parameter == "gethth")
            {
                cr.SpecialIndetity = BusinessTool.GetHeTongH(this.txtYongHuH.Text);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                e.Result = cr.ToString();
                return;
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            //根据操作人加载管理部门(站点)
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANMC", "ZHANDIANBH", "-", string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];
            this.txtZhanDian.Text = dtZhanDian.Rows[0]["TEXT"].ToString();
            string zhendianBH = dtZhanDian.Rows[0]["VALUE"].ToString();
            PageTools.LoadCombox(this.cmbGuanLiK,PageTools.eLoadType.管理块,BusinessTool.ZHANDIANBH(),null,null);
            //加载行政区
            PageTools.LoadCombox(this.cmbXingZhengQ,PageTools.eLoadType.行政区,BusinessTool.ZHANDIANBH(),null,null);
            this.txtXingZhengQ.Text = this.cmbXingZhengQ.Value.ToString();
            //操作员站点为本部时 加载局信息
            if (this.txtZhanDian.Text.Contains("本部") || this.txtZhanDian.Text.Contains("中心")||LoginInfo.CurrentUser.UserID==99999)
            {
                this.cmbJu.ReadOnly = false;
                PageTools.BindComboBox(
                    this.cmbJu, BusinessTool.GetTextAndValue(
                        "YS_JX_JUXINX", "S_MINGCHENG", "S_BIANHAO", null, "I_LEIXING=1"
                    ).Tables[0]
                );
                PageTools.LoadComboxGongSi(this.cmbGongSi, Convert.ToString(this.cmbJu.Value), null);
            }
            else
            {
                this.cmbJu.ClientEnabled = true;
                this.cmbGongSi.ClientEnabled = true;
            }
            //加载业务员
            PageTools.LoadCombox(this.cmbYeWuY,PageTools.eLoadType.业务员,false,null,null);
            //加载用水性质
            PageTools.BindComboBox(
                 this.cmbYongShuiXZ, BusinessTool.GetTextAndValue(
                 "YS_JX_YONGSHUIXZ", "S_MINGCHENG", "S_BIANMA", "-", string.Format("I_TYPE={0}", this.txtZhanDian.Text.Contains("本部") ? 1 : 0)
                 ).Tables[0]
             );
            if (this.cmbYongShuiXZ.Items.Count != 0)
            {
                this.cmbYongShuiXZ.SelectedIndex = 0;
            }
            //加载考核复用
            WordsManager manger = new WordsManager();
            PageTools.BindComboBox(this.cmbKaoHeFY, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.考核复用, "-"));
            if (this.cmbKaoHeFY.Items.Count != 0)
            {
                this.cmbKaoHeFY.SelectedIndex = 0;
            }
            //加载涉水对象代码
            PageTools.BindComboBox(
                 this.cmbSheShuiDXDM, BusinessTool.GetTextAndValue(
                 "YS_JX_HANGYELX", "S_SHESHUIDXFLMC", "S_SHESHUIDXFLDM","-", null
                 ).Tables[0]
             );
            if (this.cmbSheShuiDXDM.Items.Count != 0)
            {
                this.cmbSheShuiDXDM.SelectedIndex = 0;
            }
            //加载证件类型
            PageTools.BindComboBox(this.cmbZhengJianLX, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.证件号类型, "-"));
            if (this.cmbZhengJianLX.Items.Count != 0)
            {
                this.cmbZhengJianLX.SelectedIndex = 0;
            }
            //加载代码类型
            PageTools.BindComboBox(this.cmbDaiMaLX, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.代码类型, "-"));
            if (this.cmbDaiMaLX.Items.Count != 0)
            {
                this.cmbDaiMaLX.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            this.txtBeiZhu.Text = "";
            this.txtGongSi.Text = "";
            this.txtHuiGuanSBS.Text = "0";
            this.txtKaiHuHM.Text = "";
            this.txtKaiHuYH.Text = "";
            this.txtLianXiBM.Text = "";
            this.txtLianXiDH.Text = "";
            this.txtLianXiR.Text = "";
            this.txtShiKaoHY.Text = "1";
            this.txtYHZH.Text = "";
            this.txtYongHuDZ.Text = "";
            this.txtYongHuH.Text = "";
            this.txtYONGHUM.Text = "";
            this.txtYouBian.Text = "";
            this.txtHeTongH.Text = "";
            this.txtZiLaiSBS.Text = "0";
            
            this.cmbGongSi.Value = "";
            this.cmbGuanLiK.Value = "";
            this.cmbJu.Value = "";
            this.cmbKaoHeFY.SelectedIndex = 0;
            this.cmbSheShuiDXDM.Value = "";
            this.cmbXingZhengQ.Value = "";
            this.cmbYeWuY.Value = "";
            this.cmbYongShuiXZ.Value = "";

            this.txtGuanLiK.Text = "";
            this.txtXingZhengQ.Text = "";
            this.txtJu.Text = "";
            this.txtGongSi.Text = "";
            this.txtYeWuY.Text = "";

            this.cbChengNuo.Checked = true;
            this.cbTuoShou.Checked = false;
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {

        }

        /// <summary>
        ///用于控制添加、修改、查看三种状态的显示
        /// </summary>
        private void Display()
        {
            switch (this.Status)
            {
                case GridViewStatus.Init:
                    btnAdd.Visible = true;
                    btnEdit.Visible = this.YONGHUXXID>0?true:false;
                    btnSave.Visible = false;
                    btnCancel.Visible = false;
                    this.btnSheZhiJH.Visible = this.YONGHUXXID > 0 ? true : false;
                    this.btnZengBiao.Visible = this.YONGHUXXID > 0 ? true : false;
                    SetText(false);
                    this.txtYongHuH.Enabled = false;
                    break;
                case GridViewStatus.Update:
                    btnAdd.Visible = false;
                    btnEdit.Visible = false;
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                    this.btnSheZhiJH.Visible = false;
                    this.btnZengBiao.Visible = false;
                    SetText(true);
                    //用户号不可编辑
                    this.txtYongHuH.Enabled = false;
                    break;
                case GridViewStatus.Add:
                    btnAdd.Visible = false;
                    btnEdit.Visible = false;
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                    this.btnSheZhiJH.Visible = false;
                    this.btnZengBiao.Visible = false;
                    SetText(true);
                    this.txtYongHuH.Enabled = true;
                    this.txtYongHuH.Focus();
                    break;
            }
        }

        /// <summary>
        /// 设置输入框状态
        /// </summary>
        /// <param name="b"></param>
        private void SetText(bool b)
        {
            foreach (var item in this.panEdit.Controls)
            {
                DevExpress.Web.ASPxWebControl control = item as DevExpress.Web.ASPxWebControl;
                if (control != null)
                {
                    control.Enabled = b;
                }
            }
            this.txtZhanDian.ClientEnabled = false;
            this.txtGuanLiK.ClientEnabled = false;
            this.txtXingZhengQ.ClientEnabled = false;
            this.txtJu.ClientEnabled = false;
            this.txtGongSi.ClientEnabled = false;
            this.txtYeWuY.ClientEnabled = false;
            this.txtZiLaiSBS.ClientEnabled = false;
            this.txtHuiGuanSBS.ClientEnabled = false;
            this.txtShiKaoHY.ClientEnabled = false;
            this.txtYSJ.ClientEnabled = b;
            this.cmbGongSi.ClientEnabled = b;
            this.cmbGuanLiK.ClientEnabled = b;
            this.cmbJu.ClientEnabled = b;
            this.cmbKaoHeFY.ClientEnabled = b;
            this.cmbSheShuiDXDM.ClientEnabled = b;
            this.cmbXingZhengQ.ClientEnabled = b;
            this.cmbYeWuY.ClientEnabled = b;
            this.cmbYongShuiXZ.ClientEnabled = b;
        }     

        /// <summary>
        /// 开户
        /// </summary>
        private void SaveData()
        {
            //当前操作为开户或开户后修改
            OperateState operateState = (this.Status == GridViewStatus.Add ? OperateState.Add : OperateState.Modify);
            int type = (this.Status == GridViewStatus.Add?0:1); 
            //判断用户号合法性
            if (this.txtYongHuH.Text.Substring(0, 2) != this.txtGuanLiK.Text)
            {
                PageTools.AlertMsg(this, "用户号前两位必需与管理块号一致！");
                return;
            }            
            //如果为托收,需要填写银行账号,开户银行,开户户名
            if (this.cbTuoShou.Checked)
            {
                if (this.txtYHZH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "银行账号不能为空！");
                    this.txtYHZH.Focus();
                    return;
                }
                if (this.txtKaiHuYH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "开户银行不能为空！");
                    this.txtKaiHuYH.Focus();
                    return;
                }
                if (this.txtKaiHuHM.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "开户户名不能为空！");
                    this.txtKaiHuHM.Focus();
                    return;
                }
            }
            //判断是否修改了银行信息(开户默认为确认)
            this._YS_YG_YONGHUXX.S_BEIZHU = this.txtBeiZhu.Text;
            this._YS_YG_YONGHUXX.I_KAOHEFY = Convert.ToDecimal(this.cmbKaoHeFY.Value);
            this._YS_YG_YONGHUXX.I_SHIKAOHY = Convert.ToInt32(this.txtShiKaoHY.Text);
            this._YS_YG_YONGHUXX.I_YONGHUZT = 0;
            //this._YS_YG_YONGHUXX.N_YSJ = Convert.ToDouble(this.txtYSJ.Text);
            this._YS_YG_YONGHUXX.S_DIZHI = this.txtYongHuDZ.Text;
            if (this.cmbGongSi.SelectedIndex != -1)
            {
                this._YS_YG_YONGHUXX.S_GONGSIBH = Convert.ToString(this.cmbGongSi.Value);
            }
            this._YS_YG_YONGHUXX.S_GUANLIKBH = this.cmbGuanLiK.Value.ToString();
            if (this.cmbJu.SelectedIndex != -1)
            {
                this._YS_YG_YONGHUXX.S_JUBIANH = Convert.ToString(this.cmbJu.Value);
            }
            this._YS_YG_YONGHUXX.S_KAIHUHM = this.txtKaiHuHM.Text;
            this._YS_YG_YONGHUXX.S_KAIHUYH = this.txtKaiHuYH.Text;
            this._YS_YG_YONGHUXX.S_LIANXIBM = this.txtLianXiBM.Text;
            this._YS_YG_YONGHUXX.S_LIANXIDH = this.txtLianXiDH.Text;
            this._YS_YG_YONGHUXX.S_LIANXIR = this.txtLianXiR.Text;
            this._YS_YG_YONGHUXX.S_SHESHUIDXDM = Convert.ToString(this.cmbSheShuiDXDM.Value);
            this._YS_YG_YONGHUXX.S_XINGZHENGQBH = this.cmbXingZhengQ.Value.ToString();
            this._YS_YG_YONGHUXX.S_YEWUY = this.cmbYeWuY.Value.ToString();
            this._YS_YG_YONGHUXX.S_YINHANGZH = this.txtYHZH.Text;
            this._YS_YG_YONGHUXX.S_YONGHUH = this.txtYongHuH.Text;
            this._YS_YG_YONGHUXX.S_YONGHUM = this.txtYONGHUM.Text;
            this._YS_YG_YONGHUXX.S_YONGSHUIXZ = Convert.ToString(this.cmbYongShuiXZ.Value);
            this._YS_YG_YONGHUXX.S_YOUBIAN = this.txtYouBian.Text;
            //站点根据所选管理块取值
            DataTable dt = BusinessTool.GetTextAndValue("YS_JX_GUANLIK", "S_GUANLIKMC", "S_ZHANDIAN", null, "S_GUANLIKH='" + this.cmbGuanLiK.Value.ToString() + "'").Tables[0];
            this._YS_YG_YONGHUXX.S_ZHANDIANBH = dt.Rows[0]["VALUE"].ToString();
            this._YS_YG_YONGHUXX.I_SHOUFEIFS = this.cbTuoShou.Checked ? 1 : 0;
            this._YS_YG_YONGHUXX.I_CHENNUOFF = this.cbChengNuo.Checked ? 1 : 0;
            this._YS_YG_YONGHUXX.S_XIUGAIR = LoginInfo.CurrentUser.UserID.ToString();
            this._YS_YG_YONGHUXX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            this._YS_YG_YONGHUXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            this._YS_YG_YONGHUXX.D_XIUGAIRQ = this._YS_YG_YONGHUXX.D_CAOZUOSJ;
            this._YS_YG_YONGHUXX.D_LIHURQ = this._YS_YG_YONGHUXX.D_CAOZUOSJ;
            this._YS_YG_YONGHUXX.N_YSJ = Convert.ToDouble(txtYSJ.Text);
            string id = "-1";
            //执行开户
            _YS_YG_YONGHUXXBLL.KaiHu(_YS_YG_YONGHUXX,type,out id);
            this._YS_YG_YONGHUXX.ID = decimal.Parse(id);
            if (id != "-1")
            {
                this._YS_YG_YONGHUXX = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXX(this._YS_YG_YONGHUXX.ID);
                _SYS_LOGBLL.Log<YS_YG_YONGHUXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "用户管理-户籍管理-开户", operateState, _YS_YG_YONGHUXX, null);
                //执行用户信息维护同步
                _spHelper.P_YS_YONGHUXXWEIHUTB(this._YS_YG_YONGHUXX.S_YONGHUH, null, 1, LoginInfo.CurrentUser.UserID.ToString(), "开户");
                //更新银行批量代理合同号
                _spHelper.P_YS_YINHANGPLDLHTHXG(this._YS_YG_YONGHUXX.S_YONGHUH, this.txtHeTongH.Text);
                //更新证件号机构代码等
                string faren = this.txtFaRen.Text.Trim() == "" ? null : this.txtFaRen.Text;
                int? zhengjianlx = this.cmbZhengJianLX.Value == null ? null : (int?)Convert.ToInt32(this.cmbZhengJianLX.Value);
                string zhengjianh = this.txtZhengJianH.Text.Trim() == "" ? null : this.txtZhengJianH.Text.Trim();
                int? daimalx = this.cmbDaiMaLX.Value == null ? null : (int?)Convert.ToInt32(this.cmbDaiMaLX.Value);
                string daima = this.txtDaiMa.Text.Trim() == "" ? null : this.txtDaiMa.Text.Trim();
                string rsno, rsmsg;
                _spHelper.P_YSYG_UPDATEEXTENDINFO(this._YS_YG_YONGHUXX.S_YONGHUH, LoginInfo.CurrentUser.UserID, faren, zhengjianlx, zhengjianh, daimalx, daima, out rsno, out rsmsg);
                //记录合同号
                this.HETONGH = this.txtHeTongH.Text;
                //记录当前操作项ID
                DataTable dtTemp = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("I_JLZT=0 and I_LEIXING=1 and S_YONGHUH='{0}'", this._YS_YG_YONGHUXX.S_YONGHUH), null);
                this.YONGHUXXID = Convert.ToInt32(dtTemp.Rows[0]["ID"]);
                this.Status = GridViewStatus.Init;
                PageTools.AlertMsg(this, "保存成功！");
                Display();
            }
            else
            {
                PageTools.AlertMsg(this, "操作失败！");
            }
        }

        /// <summary>
        /// 给输入框赋值
        /// </summary>
        private void SetData()
        {
            _YS_YG_YONGHUXX = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXX(this.YONGHUXXID);
            this.txtBeiZhu.Text = this._YS_YG_YONGHUXX.S_BEIZHU;
            this.txtHeTongH.Text = this.HETONGH;
            this.txtKaiHuHM.Text = this._YS_YG_YONGHUXX.S_KAIHUHM;
            this.txtKaiHuYH.Text = this._YS_YG_YONGHUXX.S_KAIHUYH;
            this.txtLianXiBM.Text = this._YS_YG_YONGHUXX.S_LIANXIBM;
            this.txtLianXiDH.Text = this._YS_YG_YONGHUXX.S_LIANXIDH;
            this.txtLianXiR.Text = this._YS_YG_YONGHUXX.S_LIANXIR;
            this.txtYHZH.Text = this._YS_YG_YONGHUXX.S_YINHANGZH;
            this.txtYongHuDZ.Text = this._YS_YG_YONGHUXX.S_DIZHI;
            this.txtYongHuH.Text = this._YS_YG_YONGHUXX.S_YONGHUH;
            this.txtYONGHUM.Text = this._YS_YG_YONGHUXX.S_YONGHUM;
            this.txtYouBian.Text = this._YS_YG_YONGHUXX.S_YOUBIAN;
            this.cbChengNuo.Checked = this._YS_YG_YONGHUXX.I_CHENNUOFF == 1;
            this.cbTuoShou.Checked = this._YS_YG_YONGHUXX.I_SHOUFEIFS == 1;
            this.cmbJu.Value = this._YS_YG_YONGHUXX.S_JUBIANH;
            this.txtJu.Text = this._YS_YG_YONGHUXX.S_JUBIANH;
            this.cmbGongSi.Value = this._YS_YG_YONGHUXX.S_GONGSIBH;
            this.txtGongSi.Text = this._YS_YG_YONGHUXX.S_GONGSIBH;
            this.cmbGuanLiK.Value = this._YS_YG_YONGHUXX.S_GUANLIKBH;
            this.txtGuanLiK.Text = this._YS_YG_YONGHUXX.S_GUANLIKBH;
            this.cmbKaoHeFY.Value = this._YS_YG_YONGHUXX.I_KAOHEFY.ToString();
            this.txtShiKaoHY.Text = this._YS_YG_YONGHUXX.I_SHIKAOHY.ToString();
            this.cmbSheShuiDXDM.Value = this._YS_YG_YONGHUXX.S_SHESHUIDXDM;
            this.cmbXingZhengQ.Value = this._YS_YG_YONGHUXX.S_XINGZHENGQBH;
            this.txtXingZhengQ.Text = this._YS_YG_YONGHUXX.S_XINGZHENGQBH;
            this.cmbYeWuY.Value = this._YS_YG_YONGHUXX.S_YEWUY;
            this.txtYeWuY.Text = this._YS_YG_YONGHUXX.S_YEWUY;
            this.cmbYongShuiXZ.Value = this._YS_YG_YONGHUXX.S_YONGSHUIXZ;
        }

        ///// <summary>
        ///// 下拉框选中变化时变更指定的文本框值
        ///// </summary>
        ///// <param name="textbox">要赋值的文件框</param>
        //private void CmbValueToTxtText(object sender, EventArgs e, DevExpress.Web.ASPxTextBox textbox)
        //{
        //    DevExpress.Web.ASPxComboBox cmb = sender as DevExpress.Web.ASPxComboBox;
        //    if (cmb.SelectedIndex != -1)
        //    {
        //        textbox.Text = cmb.Value.ToString();
        //    }
        //    cmb.Focus();
        //}

        ///// <summary>
        ///// 根据局重新加载对应的公司
        ///// </summary>
        //private void LoadGongSiByJu()
        //{
        //    DataTable table = BusinessTool.GetTextAndValue(
        //               "YS_JX_GONGSIXX", "S_MINGCHENG", "S_BIANHAO", null, string.Format("S_JUBIANH='{0}' and I_LEIXING=0", this.cmbJu.Value)
        //           ).Tables[0];
        //    if (table.Rows.Count > 0)
        //    {
        //        PageTools.BindComboBox(this.cmbGongSi, table);
        //        this.cmbGongSi.SelectedIndex = 0;
        //        this.txtGongSi.Text = this.cmbGongSi.Value.ToString();
        //    }
        //    else
        //    {
        //        this.cmbGongSi.Items.Clear();
        //        this.cmbGongSi.Text = "";
        //        this.cmbGongSi.Value = "";
        //        this.txtGongSi.Text = "";
        //    }
        //}
              
        /// <summary>
        /// 保存验证
        /// </summary>
        /// <returns></returns>
        private bool ValidateData()
        {
            if (this.txtYongHuH.Text == "")
            {
                PageTools.AlertMsg(this,"用户号不能为空！");
                this.txtYongHuH.Focus();
                return false;
            }
            if (this.txtYongHuH.Text.Length!=7||!PageTools.ValidateString(this.txtYongHuH.Text,PageTools.eValidateType.数字))
            {
                PageTools.AlertMsg(this,"用户号应为7位数字！");
                this.txtYongHuH.Focus();
                return false;
            }            
            if (this.txtGuanLiK.Text == "")
            {
                PageTools.AlertMsg(this,"请选择管理块！");
                this.cmbGuanLiK.Focus();
                return false;
            }
            //判断用户号合法性
            if (this.txtYongHuH.Text.Substring(0, 2) != this.txtGuanLiK.Text)
            {
                PageTools.AlertMsg(this,"用户号前两位必需与管理块号一致！");
                this.txtYongHuH.Focus();
                return false;
            }
            if (this.Status == GridViewStatus.Add)
            {
                //判断用户号是否重复
                if (_YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("S_YONGHUH='{0}' and ID<>{1}", this.txtYongHuH.Text, _YS_YG_YONGHUXX.ID), null).Rows.Count > 0)
                {
                    PageTools.AlertMsg(this, "该用户号系统中已有使用,请更换！");
                    return false;
                }
            }
            if (this.txtXingZhengQ.Text == "")
            {
                PageTools.AlertMsg(this, "请选择行政区！");
                this.cmbXingZhengQ.Focus();
                return false;
            }
            if (this.txtZhanDian.Text.Contains("本部"))
            {
                if (this.txtJu.Text == "")
                {
                    PageTools.AlertMsg(this,"请选择局！");
                    this.cmbJu.Focus();
                    return false;
                }
            }
            if (this.txtYeWuY.Text == "")
            {
                PageTools.AlertMsg(this,"请选择业务员！");
                this.cmbYeWuY.Focus();
                return false;
            }
            if (this.txtYONGHUM.Text == "")
            {
                PageTools.AlertMsg(this,"用户名不能为空！");
                this.txtYONGHUM.Focus();
                return false;
            }
            if (this.txtYongHuDZ.Text == "")
            {
                PageTools.AlertMsg(this,"用户地址不能为空！");
                this.txtYongHuDZ.Focus();
                return false;
            }
            if (this.txtYouBian.Text == "")
            {
                PageTools.AlertMsg(this, "邮编不能为空！");
                this.txtYouBian.Focus();
                return false;
            }

            //如果为托收,需要填写银行账号,开户银行,开户户名
            if (this.cbTuoShou.Checked)
            {
                if (this.txtYHZH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this, "银行账号不能为空！");
                    this.txtYHZH.Focus();
                    return false;
                }
                if (!PageTools.ValidateString(this.txtYHZH.Text, PageTools.eValidateType.数字))
                {
                    PageTools.AlertMsg(this,"请输入数字类型！");
                    this.txtYHZH.Focus();
                    return false;
                }
                if (this.txtKaiHuYH.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this,"开户银行不能为空！");
                    this.txtKaiHuYH.Focus();
                    return false;
                }
                if (this.txtKaiHuHM.Text.Trim() == "")
                {
                    PageTools.AlertMsg(this,"开户户名不能为空！");
                    this.txtKaiHuHM.Focus();
                    return false;
                }
            }
            return true;
        }

        #endregion        
    }
}